//
//  CourseSignUpCycleTableViewCell.m
//  TeacherNet
//
//  Created by slz on 2017/12/6.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "CourseSignUpCycleTableViewCell.h"

@implementation CourseSignUpCycleTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        _sortLabel = [UILabel new];
        _sortLabel.textColor = kLight_TextColor_Light_More_Dark;
        _sortLabel.fontSize = kFont_Size_Cotent_Nomal;
        [self.contentView addSubview:_sortLabel];
        [_sortLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(20);
            make.width.mas_equalTo(10);
            make.top.mas_equalTo(20);
        }];
        
        _courseTitle = [UILabel new];
        _courseTitle.textColor = kLight_TextColor_Light_More_Dark;
        _courseTitle.fontSize = kFont_Size_Cotent_Nomal;
        [self.contentView addSubview:_courseTitle];
        [_courseTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_sortLabel.mas_right).offset(15);
            make.centerY.mas_equalTo(_sortLabel.mas_centerY);
            make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
        }];
        
        _courseTypeImageView = [UIImageView new];
        [self.contentView addSubview:_courseTypeImageView];
        [_courseTypeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(16, 16));
            make.left.mas_equalTo(_courseTitle.mas_left);
            make.top.mas_equalTo(_courseTitle.mas_bottom).offset(12);
        }];
        
        _courseTypeLabel = [UILabel new];
        _courseTypeLabel.textColor = kLight_TextColor_Default;
        _courseTypeLabel.fontSize = kFont_Size_Cotent_Middle;
        [self.contentView addSubview:_courseTypeLabel];
        [_courseTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseTypeImageView.mas_right).offset(4);
            make.centerY.mas_equalTo(_courseTypeImageView.mas_centerY);
        }];
        
        _courseStateLabel = [UILabel new];
        _courseStateLabel.textColor = kLight_TextColor_Default;
        _courseStateLabel.fontSize = kFont_Size_Cotent_Middle;
        [self.contentView addSubview:_courseStateLabel];
        [_courseStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_courseTypeLabel.mas_right).offset(20);
            make.centerY.mas_equalTo(_courseTypeLabel.mas_centerY);
        }];
        
        UIView* lineView = [UIView quickLineColorView];
        [self.contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.and.bottom.mas_equalTo(self.contentView);
            make.height.mas_equalTo(.5);
        }];
    }
    return self;
}

-(void)layoutWithModel:(CourseSignUpCycleModel *)model andCurrentCourseId:(NSString *)courseId;
{
    BOOL showCurrentCourseState = [model.courseId isEqualToString:courseId];
    
    _sortLabel.text = model.courseSort;
    _courseTitle.text = model.title;
    
    _sortLabel.textColor = showCurrentCourseState ?  kButtonColorBlue : kLight_TextColor_Light_More_Dark;
    _courseTitle.textColor = showCurrentCourseState ?  kButtonColorBlue : kLight_TextColor_Light_More_Dark;
    
    NSString * typeString;
    NSString * imageString = @"course_type_book";
    NSString * stateString;
    switch (model.courseType) {
        case 0:
            typeString = @"试卷";
            imageString = @"course_type_exam";
            break;
            case 1:
            typeString = @"文档";
            imageString = @"course_type_book";
            break;
            case 2:
            typeString = @"视频";
            imageString = @"course_type_radio";
            break;
            case 3:
            typeString = @"讨论";
            imageString = @"course_type_talk";
            break;
            case 4:
            typeString = @"作业";
            imageString = @"course_type_homework";
            break;
        default:
            break;
    }
    
    switch (model.studyed) {
        case 0:
            stateString = @"未学习";
            break;
            case 1:
            stateString = @"已学习";
            break;
            case 2:
            stateString = @"学习中";
            break;
        default:
            stateString = @"未学习";
            break;
    }
    
    _courseTypeLabel.text = typeString;
    _courseTypeImageView.image = [UIImage imageNamed:imageString];
    _courseStateLabel.text = stateString;
}

@end
